package com.youth.koodoReaderManager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youth.koodoReaderManager.entity.DictHistory;
import com.youth.koodoReaderManager.service.DictHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/dictHistories")
@Api(tags = "字典历史管理", description = "提供字典历史的增删改查及分页查询接口")
public class DictHistoryController {

    private final DictHistoryService dictHistoryService;

    @Autowired
    public DictHistoryController(DictHistoryService dictHistoryService) {
        this.dictHistoryService = dictHistoryService;
    }

    @PostMapping
    @ApiOperation(value = "创建新的字典历史记录", notes = "添加新的字典历史记录")
    public boolean createDictHistory(@RequestBody DictHistory dictHistory) {
        return dictHistoryService.save(dictHistory);
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新字典历史记录", notes = "根据字典历史ID更新字典历史记录")
    public boolean updateDictHistory(@PathVariable String id, @RequestBody DictHistory dictHistory) {
        return dictHistoryService.updateById(dictHistory);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除字典历史记录", notes = "根据字典历史ID删除字典历史记录")
    public boolean deleteDictHistory(@PathVariable String id) {
        return dictHistoryService.removeById(id);
    }

    @GetMapping
    @ApiOperation(value = "分页查询字典历史记录", notes = "根据查询条件分页获取字典历史记录列表")
    public IPage<DictHistory> pageQueryDictHistories(@RequestParam(defaultValue = "1") int current,
                                                     @RequestParam(defaultValue = "10") int size,
                                                     @RequestBody(required = false) DictHistory dictHistory) {
        // 创建分页对象
        IPage<DictHistory> page = new Page<>(current, size);
        // 调用服务层执行分页查询
        return dictHistoryService.pageQuery(page, dictHistory);
    }
}